package com.kuaidao.sys.exception;

import com.kuaidao.common.constant.SysErrorCodeEnum;
import com.kuaidao.common.entity.JSONResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * 系统管理全局异常处理
 */
@RestControllerAdvice
public class GlobalExceptionHandler {
    private Logger logger = LoggerFactory.getLogger(getClass());

    @ExceptionHandler(value = Exception.class)
    public JSONResult<Object> defaultExceptionHandler(HttpServletRequest req, Exception e) {
        logger.error("系统管理接口调用异常：{}", e);

        return new JSONResult<Object>().fail(SysErrorCodeEnum.ERR_SYSTEM.getCode(),
                SysErrorCodeEnum.ERR_SYSTEM.getMessage());
    }

}
